package com.itheima.entry.dao;


import com.itheima.entry.domain.UserInfo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class SuperSave implements Runnable {
/*
每隔5秒保存一次用户数据
 */
    private ArrayList<UserInfo> list;
    private UserInfo currentUser;

    public SuperSave(ArrayList<UserInfo> list) {
        this.list = list;
    }

    public SuperSave(ArrayList<UserInfo> list, UserInfo currentUser) {
        this.list = list;
        this.currentUser = currentUser;
    }

    @Override
    public void run() {
        while (true) {
            try {


                ObjectOutputStream obo = new ObjectOutputStream(new FileOutputStream("D:\\heima_system\\backup\\userList.txt"));
                obo.writeObject(list);
                obo.flush();
                obo.close();
                Thread.sleep(5000);
            } catch (InterruptedException | IOException e) {
                e.printStackTrace();
            }


        }
    }
}
